import { GlobalClass } from "../../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { ItemData } from "../../../../resource/info/ItemData";
import { AchievementBonusItem } from "../../../achievement/item/AchievementBonusItem";
import { BaseItem } from "../../../common/BaseItem";
import { FilterConst } from "../../../../../component/gconst/FilterConst";
import { RuneUtil } from "../RuneUtil";
import { Cache } from "../../../../cache/Cache";
import { ItemInfo } from "../../../../resource/info/ItemInfo";
import { ObjCreate } from "../../../common/ObjCreate";
import { Language } from "../../../../../../extend/language/Language";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../../com/mui/controls/GButton";
type int = number;
//class SkillRuneComposeStuffItem
    
    export  class SkillRuneComposeStuffItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            return;
        }

        public get swallowStatus(): int
        {
            return this._swallowStatus;
        }

        public setLock(): void
        {
            this.clearIcon();
            this.enableDetailView(false);
            this._item = GlobalClass.getBitmap(ImagesConst.LockBig);
            this._item.x = 11;
            this._item.y = 10;
            this.addChild(this._item);
            return;
        }

        public update(arg1: ItemData, arg2: ItemData, arg3: Boolean=false): void
        {
            this._data = arg1;
            this._swallowed = arg3;
            this._targetData = arg2;
            this.clearIcon();
            if (arg1 == null) 
            {
                this.enableDetailView(false);
                return;
            }
            this.enableDetailView(true);
            this._item = new AchievementBonusItem(this._data.itemCode, 1);
            var loc1;
            this._item.y = loc1 = 3;
            this._item.x = loc1;
            BaseItem(this._item).toolTipDataFunction = this.getToolTipData;
            this.addChild(this._item);
            if (!this._swallowed && (this.getAllMyCodes(this._data) == null || this.getAllMyCodes(this._data).length == 0)) 
            {
                this._item.filters = [FilterConst.colorFilter];
            }
            else 
            {
                this._item.filters = [];
            }
            this._txtName.htmlText = arg1.htmlName;
            this.updateStatus();
            return;
        }

        /* internal  */getToolTipData(arg1)
        {
            return RuneUtil.getRunesHandbookDesc(this._data.itemCode);
        }

        /* internal  */getAllMyCodes(arg1: ItemData): Array<any>
        {
            var loc1=Cache.instance.rune.getMyBackPackRunesByCode(arg1.itemCode);
            var loc2=Cache.instance.rune.getMyRolePackRunesByCode(arg1.itemCode);
            var loc3=RuneUtil.getBindInfoByUnBindCode(arg1.itemCode);
            var loc4=-1;
            if (loc3 && loc3.length > 0) 
            {
                loc4 = ItemInfo(loc3[0]).item.code;
            }
            if (loc4 != -1) 
            {
                loc1 = Cache.instance.rune.getMyBackPackRunesByCode(loc4).concat(loc1);
                loc2 = Cache.instance.rune.getMyRolePackRunesByCode(loc4).concat(loc2);
            }
            return loc1.concat(loc2);
        }

        /* internal  */enableDetailView(arg1: Boolean): void
        {
            this._bg.visible = arg1;
            this._txtName.visible = arg1;
            this._txtStatus.visible = arg1;
            this._btnSwallow.visible = arg1;
            return;
        }

        /* internal  */clearIcon(): void
        {
            if (this._item != null) 
            {
                if (this._item.parent != null) 
                {
                    this._item.parent.removeChild(this._item);
                }
            }
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=null;
            this._bg = ObjCreate.createBg(-25, 40, 84, 48, this);
            this._bg.visible = false;
            this._txtName = ObjCreate.createGTextField("", -25, 44, 84, 20, this);
            this._txtName.textColor = 16711927;
            loc1 = this._txtName.defaultTextFormat;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._txtName.defaultTextFormat = loc1;
            this._txtStatus = ObjCreate.createGTextField("", -25, 61, 84, 37, this);
            this._txtStatus.textColor = 65317;
            loc1 = this._txtStatus.defaultTextFormat;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._txtStatus.defaultTextFormat = loc1;
            this._btnSwallow = ObjCreate.createGButton("", -15, 62, 65, 24, this, "ButtonRed");
            this._txtStatus.htmlText = Language.getString(80073);
            this._btnSwallow.label = this._txtStatus.text;
            return;
        }

        /* internal  */updateStatus(): void
        {
            this._bg.height = 42;
            this._btnSwallow.visible = false;
            if (this._swallowed) 
            {
                this._txtStatus.visible = true;
                this._txtStatus.htmlText = Language.getString(80072);
                this._swallowStatus = SkillRuneComposeStuffItem.SwallowStatusSwallowed;
            }
            else if (this.gotItemInBackpack() || this.gotItemInEquiped()) 
            {
                this._swallowStatus = SkillRuneComposeStuffItem.SwallowStatusCanSwallow;
                this._txtStatus.htmlText = Language.getString(80325);
            }
            else 
            {
                this._txtStatus.visible = true;
                this._txtStatus.htmlText = Language.getString(80074);
                this._swallowStatus = SkillRuneComposeStuffItem.SwallowStatusHaveNo;
            }
            return;
        }

        /* internal  */clickLinkHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */hasSwallowed(): Boolean
        {
            var loc2=0;
            var loc1=0;
            while (loc1 < this._targetData.runeSwallowCodes.length) 
            {
                loc2 = int(this._targetData.runeSwallowCodes[loc1]);
                if (loc2 == this._data.itemCode) 
                {
                    return true;
                }
                ++loc1;
            }
            return false;
        }

        /* internal  */gotItemInEquiped(): Boolean
        {
            var loc1=this._data.itemCode;
            var loc2=Cache.instance.pack.runePackCache.getItemByCode(this._data.itemCode);
            if (loc2 != null) 
            {
                return true;
            }
            var loc3=RuneUtil.getBindInfoByUnBindCode(loc1);
            if (loc3 && loc3.length > 0) 
            {
                loc2 = Cache.instance.pack.runePackCache.getItemByCode(ItemInfo(loc3[0]).item.code);
            }
            if (loc2 != null) 
            {
                return true;
            }
            return false;
        }

        /* internal  */gotItemInBackpack(): Boolean
        {
            var loc1=this._data.itemCode;
            var loc2=Cache.instance.pack.backPackCache.getItemByCode(this._data.itemCode);
            if (loc2 != null) 
            {
                return true;
            }
            var loc3=RuneUtil.getBindInfoByUnBindCode(loc1);
            if (loc3 && loc3.length > 0) 
            {
                loc2 = Cache.instance.pack.backPackCache.getItemByCode(ItemInfo(loc3[0]).item.code);
                if (loc2 != null) 
                {
                    return true;
                }
            }
            return false;
        }

        public static /* const */SwallowStatusSwallowed: int=1;

        public static /* const */SwallowStatusCanSwallow: int=2;

        public static /* const */SwallowStatusHaveNo: int=3;

        /* internal */ /* var */_data: ItemData;

        /* internal */ /* var */_targetData: ItemData;

        /* internal */ /* var */_txtStatus: GTextFiled;

        /* internal */ /* var */_txtName: GTextFiled;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_item: Object /* flash.display.DisplayObject */;

        /* internal */ /* var */_swallowed: Boolean;

        /* internal */ /* var */_btnSwallow: GButton;

        /* internal */ /* var */_swallowStatus: int;
    }
